%
% vcycle_sym.m
%
%   recursive vcycle code with symmetric smoother
%
function v = vcycle_sym(u,f,level);
  
  % data structure with the matricies, and parameters
  %
  global mg_matrix
  global mg_param

  % multigrid parameters
  %
  nu1      = mg_param.nu1;
  nu2      = mg_param.nu2;
  minlevel = mg_param.minlevel;
  
  % if on the last level solve the muthafucka 
  %
  if( level == minlevel )
    B = mg_matrix.A{level};
    if (condest(B)>1.e12)
        sz = size(B);
        B = [B; ones(1,sz(2))];
        f = [f;0];
    end
    v = B\f;
  else
    
    % presmooth
    %
    v = gs_lex_sym(u,mg_matrix.A{level},f,nu1);
        

    % compute residual
    %
    r = f - mg_matrix.A{level}*v;
    
    % restrict
    %
    fc = mg_matrix.Ir{level}*r;
    
    % initialize
    %
    uc = 0.0*fc;
    
    % solve the error equation, recursively
    %
    ec = vcycle_sym(uc,fc,level-1);
    
    % correct
    %
    v = v + mg_matrix.Ip{level} * ec;
  
    % post smoothing
    %
    v = gs_lex_sym(v,mg_matrix.A{level},f,nu2);
  
  end
  
  
